<template>
<div>
  <!--查询-->
  <SchoolTeachingClassQuery
    :query="query"
    :loadTableList="loadTableList"
    :clearQuery="clearQuery"
    :removeQueryField="removeQueryField"
  />
  <!--表格-->
  <SchoolTeachingClassTable
    :table="table"
    :loadTableList="loadTableList"
    :changePageSize="changePageSize"
    :changePage="changePage"
    @addRow="addRow"
    @editRow="editRow"
    @addStudents="addStudents"
  />
  <SchoolTeachingClassAddOrEditDialog
    ref="dialogRef"
    :table="table"
    :action="action"
  />
</div>
</template>

<script lang="ts" setup>
// 引入教学班表格页面
import SchoolTeachingClassTable from '@/views/page/tearchertack/mycourse/details/teachingmanage/SchoolTeachingClassTable.vue';
// 引入查询
import SchoolTeachingClassQuery from '@/views/page/tearchertack/mycourse/details/teachingmanage/SchoolTeachingClassQuery.vue';
// 引入添加编辑
import SchoolTeachingClassAddOrEditDialog from '@/views/page/tearchertack/mycourse/details/teachingmanage/SchoolTeachingClassAddOrEditDialog.vue';
// 用于初始化
import useTableList from '@/api/common/useTableList';
import { getCurrentInstance, provide, ref } from 'vue';
// 引入学生类型
import { TeachingClass } from '@/types/interface/school_interface';
import Request from '@/api/request/request';

const { proxy } = getCurrentInstance();
const courseId = ref(sessionStorage.getItem('courseId'));
// 表格工具必备参数
const {
  table, query, loadTableList, removeQueryField, clearQuery, changePageSize, changePage,
} = useTableList(`${proxy.$urls.API_URL_BACKSTAGE_SCHOOLTEACHINGTASK_MANAGE}?courseId=${courseId.value}`);
// 将表格刷新函数到子容器
provide('loadTableList', loadTableList);
// 表单对象，可以在这里加上默认值
const action = ref();
const dialogRef = ref();
// 点击添加按钮，交由父组件处理
const addRow = (id: number) => {
  // 添加表单的初始值
  const form = {
    online: 'false',
  };
  // 表单的模式为添加
  action.value = 'post';
  // 打开对话框
  dialogRef.value!.openDialog(form);
};
// 编辑操作
const editRow = async (row: TeachingClass) => {
  action.value = 'put';
  // 读取账户信息
  const resData: any = await new Request(`${proxy.$urls.API_URL_BACKSTAGE_SCHOOLTEACHINGTASK_MANAGE}/${row.id}`).get();
  if (resData.success) {
    const form = resData.data;
    dialogRef.value!.openDialog(JSON.parse(JSON.stringify(form)));
  }
};
</script>
<style scoped>

</style>
